﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;

namespace ProjetoComperio.Test.FakeData
{
    public class FakeComperioEntitiesDataModel : IComperioEntitiesDataModel
    {

        public void Dispose()
        {

        }
        public void SaveChanges()
        {

        }
        public bool IsInitialized
        {
            get
            {
                return true;
            }
            set
            {
            }
        }

        #region Database functions
        public void DeleteDatabase()
        {
            throw new NotImplementedException();
        }

        public void CreateDatabase()
        {
            throw new NotImplementedException();
        }

        public bool DatabaseExists()
        {
            throw new NotImplementedException();
        }
        #endregion

        #region IDbSets



        #region AcademicOrganizations
        private FakeObjectSet<AcademicOrganization> _academicOrganizations;
        public IDbSet<AcademicOrganization> AcademicOrganizations
        {
            get
            {
                if (_academicOrganizations == null)
                {
                    List<AcademicOrganization> _data = new List<AcademicOrganization>();
                    _data.Add(new AcademicOrganization() { AcademicOrganizationID = 1, Name = "IST-Rio" });
                    _data.Add(new AcademicOrganization() { AcademicOrganizationID = 2, Name = "UFRJ" });
                    _academicOrganizations = new FakeObjectSet<AcademicOrganization>(_data);
                }
                return _academicOrganizations;


            }
        }

        #endregion

        public IDbSet<AcademicOrganizationType> AcademicOrganizationTypes
        {
            get { throw new NotImplementedException(); }
        }

        public IDbSet<AgeRange> AgeRanges
        {
            get { throw new NotImplementedException(); }
        }

        public IDbSet<Comment> Comments
        {

            get
            {
                throw new NotImplementedException();

            }
        }

        public IDbSet<Subject> Subjects
        {

            get
            {
                throw new NotImplementedException();

            }
        }



        #region Course
        private FakeObjectSet<Course> _courses;
        public IDbSet<Course> Courses
        {
            get
            {
                if (_courses == null)
                {
                    ISet<Course> _data = new HashSet<Course>();
                    _data.Add(new Course() { CourseID = 1, Name = "CC" });
                    _data.Add(new Course() { CourseID = 1, Name = "AS" });
                    _courses = new FakeObjectSet<Course>(_data);
                }
                return _courses;

            }
        }
        #endregion

        #region EducationLevel
        private FakeObjectSet<EducationLevel> _educationLevels;
        public IDbSet<EducationLevel> EducationLevels
        {
            get
            {

                if (_educationLevels == null)
                {
                    ISet<EducationLevel> _data = new HashSet<EducationLevel>();
                    _data.Add(new EducationLevel(1, "Primario"));
                    _data.Add(new EducationLevel(2, "Secundario"));
                    _data.Add(new EducationLevel(3, "Terciario"));
                    _educationLevels = new FakeObjectSet<EducationLevel>(_data);
                }
                return _educationLevels;
            }
        }


        #endregion

        public IDbSet<Context> Contexts
        {
            get { throw new NotImplementedException(); }
        }


        #region Contributions
        private FakeObjectSet<Contribution> _contributions;
        private ISet<Contribution> fillContributionsSet()
        {
            ISet<Contribution> _data = new HashSet<Contribution>();
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidEducationalITApplication());
            _data.Add(GenerateValidContribution());
            _data.Add(GenerateValidContribution());
            _data.Add(GenerateValidContribution());
            _data.Add(GenerateValidProject());
            _data.Add(GenerateValidProject());
            _data.Add(GenerateValidProject());
            _data.Add(GenerateValidProject());
            _data.Add(GenerateValidEvent());
            _data.Add(GenerateValidEvent());
            return _data;

        }
        private Contribution GenerateValidContribution()
        {
            Contribution contribution = new Contribution();
            contribution.AcademicPersonID = 2;
            contribution.ContributionID = new Random(100).Next();
            contribution.Description = "Contribution TO Test";
            contribution.RegisterDate = DateTime.Now;
            contribution.SourceInfo = "SourceInfo";
            contribution.Title = "Contribution" + new Random(100).Next().ToString();
            return contribution;
        }
        private EducationalITApplication GenerateValidEducationalITApplication()
        {
            String value = new Random().Next().ToString();
            EducationalITApplication educationalITApplication = new EducationalITApplication();
            educationalITApplication.AcademicPersonID = 1;
            educationalITApplication.AdditionalInfo = "Add Info" + value;
            educationalITApplication.ContributionID = new Random(1).Next();
            educationalITApplication.Description = "Just some data to test" + value;
            educationalITApplication.IsFree = true;
            educationalITApplication.IsOpenSource = true;
            educationalITApplication.RegisterDate = DateTime.Now;
            educationalITApplication.SourceInfo = "www.higorcesar.com.br";
            educationalITApplication.Title = "Teste" + value;
            educationalITApplication.UseInstructions = "testtext" + value;
            return educationalITApplication;
        }
        private Project GenerateValidProject()
        {
            Project project = new Project();
            project.AcademicPersonID = 2;
            project.ContributionID = new Random(200).Next();
            project.Description = "Project TO Test";
            project.RegisterDate = DateTime.Now;
            project.SourceInfo = "SourceInfo";
            project.Title = "Contribution" + new Random(200).Next().ToString();
            return project;
        }
        private Event GenerateValidEvent()
        {
            Event _event = new Event();
            _event.AcademicPersonID = 2;
            _event.Author = "Higor";
            _event.AuthorDescription = "Developer";
            _event.ContributionID = new Random(300).Next();
            _event.Description = "TDescription";
            _event.Details = "Just some details";
            _event.EndDate = DateTime.Now.AddDays(1);
            _event.Location = "Somewhere";
            _event.RegisterDate = DateTime.Now;
            _event.Subject = "Subject";
            _event.Title = "Event Test";
            return _event;
        }
        public IDbSet<Contribution> Contributions
        {
            get
            {
                if (_contributions == null)
                {
                    _contributions = new FakeObjectSet<Contribution>(fillContributionsSet());
                }
                return _contributions;

            }
        }
        public IDbSet<ContributionItem> ContributionItems
        {
            get { throw new NotImplementedException(); }

        }

        #endregion


        public IDbSet<global::ProjetoComperio.DataLayer.Entities.Environment> Environments
        {
            get { throw new NotImplementedException(); }
        }

        public IDbSet<KnowledgeArea> KnowledgeAreas
        {
            get { throw new NotImplementedException(); }
        }

        public IDbSet<NewContributionMember> NewContributionMembers
        {
            get { throw new NotImplementedException(); }
        }


        #region Objectset People
        private FakeObjectSet<Person> _people;

        public IDbSet<Person> People
        {
            get
            {
                if (_people == null)
                {
                    IList<Person> _data = new List<Person>();
                    _data.Add(GenerateValidPerson());
                    _data.Add(GenerateValidPerson());
                    _data.Add(GenerateValidPerson());
                    _data.Add(GenerateValidPerson());
                    _people = new FakeObjectSet<Person>(_data);
                }
                return _people;
            }
        }

        public static Person GenerateValidPerson()
        {
            Person person = new Person();
            person.Name = "Higor";
            person.Email = "higor@projetocomperio.org";
            person.Country = "Brasil";
            person.State = "RJ";
            person.Neighbourhood = "Vila da Penha";
            person.ZipCode = "21221120";
            person.Street = "Rua ABC";
            person.AddressNumber = "120";
            person.City = "Rio de Janeiro";
            person.WebPage = "webPage";
            person.BirthDate = DateTime.Today.Date;
            return person;
        }

        #endregion

        public IDbSet<Platform> Platforms
        {
            get { throw new NotImplementedException(); }
        }
        #endregion

        #region IComperioEntitiesDataModel Members


        System.Data.Entity.IDbSet<AcademicOrganization> IComperioEntitiesDataModel.AcademicOrganizations
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<AcademicOrganizationType> IComperioEntitiesDataModel.AcademicOrganizationTypes
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<AgeRange> IComperioEntitiesDataModel.AgeRanges
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Course> IComperioEntitiesDataModel.Courses
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Comment> IComperioEntitiesDataModel.Comments
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Subject> IComperioEntitiesDataModel.Subjects
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<EducationLevel> IComperioEntitiesDataModel.EducationLevels
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Context> IComperioEntitiesDataModel.Contexts
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Contribution> IComperioEntitiesDataModel.Contributions
        {
            get { return Contributions; }
        }

        System.Data.Entity.IDbSet<global::ProjetoComperio.DataLayer.Entities.Environment> IComperioEntitiesDataModel.Environments
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<KnowledgeArea> IComperioEntitiesDataModel.KnowledgeAreas
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<NewContributionMember> IComperioEntitiesDataModel.NewContributionMembers
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Person> IComperioEntitiesDataModel.People
        {
            get { throw new NotImplementedException(); }
        }

        System.Data.Entity.IDbSet<Platform> IComperioEntitiesDataModel.Platforms
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}
